//
//  HHSheetSample.swift
//  HHSwiftuiPractice
//
//  Created by YL-Hong on 2023/10/7.
// Sheet

import SwiftUI

struct HHSheetSample: View {
    @State var showFirstSheet: Bool = false
    @State var showSecondSheet: Bool = false
    
    var body: some View {
        ZStack {
                  Color.yellow
                      .edgesIgnoringSafeArea(.all)
                  
                  HStack {
                      Button {
                          showFirstSheet.toggle()
                      } label: {
                          Text("first")
                              .foregroundColor(Color.black)
                              .font(.headline)
                              .frame(width: 80, height: 50)
                              .background(Color.white.cornerRadius(10))
                      }
                      
                      Button {
                          showSecondSheet.toggle()
                      } label: {
                          Text("Second")
                              .foregroundColor(Color.black)
                              .font(.headline)
                              .frame(width: 80, height: 50)
                              .background(Color.white.cornerRadius(10))
                      }
                  }
                  .sheet(isPresented: $showFirstSheet) {
                      FirstScreen(isPresented: $showFirstSheet)
                  }
//                  .sheet(isPresented: $showSecondSheet) {
//                      SecondScreen(isPresented: $showSecondSheet)
//                  }
                  .fullScreenCover(isPresented: $showSecondSheet) {
                      SecondScreen(isPresented: $showSecondSheet)
                  }
            
              }
        
    }
}

struct HHSheetSample_Previews: PreviewProvider {
    static var previews: some View {
        HHSheetSample()
    }
}

struct SecondScreen: View {
    
    @Binding var isPresented: Bool
    
    var body: some View {
        ZStack(alignment: .topLeading) {
            Color.green
                .edgesIgnoringSafeArea(.all)
            
            HStack(alignment: .top) {
                Spacer()
                Button {
                    isPresented.toggle()
                } label: {
                    Text("CLOSED")
                        .foregroundColor(Color.green)
                        .font(.headline)
                        .padding()
                        .background(Color.white.cornerRadius(10))
                }
            }
            .padding(.horizontal, 10)
        }
    }
}


struct FirstScreen: View {
    
    @Binding var isPresented: Bool
    
    
    var body: some View {
        ZStack(alignment: .topLeading) {
            Color.orange
                .edgesIgnoringSafeArea(.all)
            
            HStack(alignment: .top) {
                Button {
                    isPresented.toggle()
                } label: {
                    Image(systemName: "xmark")
                        .foregroundColor(Color.white)
                        .padding(20)
                        .font(.headline)
                }
            }
            .padding(.horizontal, 10)
        }
    }
}

